/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Farcast;

import javax.microedition.lcdui.*;

/**
 *
 * @author Jeroen Rikhof
 */
public class EditTxtForm extends Form implements CommandListener {
    private Farcast midlet;
    private String string;
    private Command cmdOk;
    private Command cmdBack;
    private TextField editField;
    
    public EditTxtForm(Farcast midlet, String s) {
        super("Edit "+s);
        System.out.println(s);
        this.midlet = midlet;
        this.string = s;
        if (s.equals("Title")){
            editField = new TextField(s, midlet.message.getMessageTitle(),80,TextField.ANY);
        }
        else if (s.equals("Text")) {
            editField = new TextField(s, midlet.message.getMessageBody(),80,TextField.ANY);
        }        
        cmdOk = new Command("OK", Command.OK, 0);
        cmdBack = new Command("Back", Command.BACK, 0);
        
        append(editField);
        addCommand(cmdOk);
        addCommand(cmdBack);
        setCommandListener(this);
    }
    
    public void commandAction (Command c, Displayable d){
        if (c == cmdBack){
            midlet.displayManager.popDisplayable();
        }
        if (c == cmdOk){
            if (string.equals("Title")){
                midlet.message.setMessageTitle(editField.getString());
            }
            else if (string.equals("Text")){
                midlet.message.setMessageBody(editField.getString());
            }
            midlet.displayManager.popDisplayable();
        }
    }
      
}
